<% layout('boilerplate') -%>
<link rel="stylesheet" href="<%= linkPath %>/css/style.css">
<!--<script src="http://tjs.sjs.sinajs.cn/open/api/js/wb.js?appkey=<%= appid %>&debug=true" type="text/javascript" charset="utf-8"></script>-->
<script type="text/javascript" src="<%= linkPath %>/js/index.js"></script>
<div class="app-wrapper">
	<div id="configObj" data-val="<%= appid %>"></div>
    <div id="wb_connect_btn"></div>
</div>
<script>
	$(function () {
        var getQueryString = function () {
            var qs = location.search.substr(1), // 获取url中"?"符后的字串
                args = {}, // 保存参数数据的对象
                items = qs.length ? qs.split("&") : [], // 取得每一个参数项,
                item = null,
                len = items.length;

            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                var name = decodeURIComponent(item[0]),
                    value = decodeURIComponent(item[1]);
                if (name) {
                    args[name] = value;
                }
            }
            return args;
        }
		var targetUrl = '<%= targetUrl %>';
		var query = getQueryString();
        var source = query['source'];
        var AuserId = query['userId'] + '_' + source ;
        var wxUrl = function (appid,url,userId) {
            var redirect_uri = url;
			return 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='+
				appid +'&redirect_uri='+ redirect_uri +'&response_type=code&' +
				'scope=snsapi_userinfo&state='+ userId +'#wechat_redirect'
        }

        var wbUrl = function (appid,url,userid) {
            return 'https://api.weibo.com/oauth2/authorize?client_id='+
                appid +'&response_type=code&redirect_uri='+url+'&state='+ userid
        }

        var qqUrl = function (appid,url,userid) {
            return 'https://graph.qq.com/oauth2.0/authorize?client_id='+
                appid +'&response_type=code&redirect_uri='+url+'&state='+ userid
        }

        var appid = $("#configObj").data('val');
        if(source == 'Wechat'){
            location.href = wxUrl(appid,targetUrl,AuserId);
		}else if(source == 'SinaWeibo'){
            location.href = wbUrl(appid,targetUrl,AuserId)
		}else if(source == 'QQ'){
            location.href = qqUrl(appid,targetUrl,AuserId)
        }
    })
</script>
